package com.smart.builder.entity;

import javax.persistence.EntityManager;

import com.smart.persistence.entity.Card;
import com.smart.persistence.service.SmartBasicCrudDAO;
import com.smart.service.util.Logging;

public class BuilderEntityCard {
	
	private static final Logging LOGGER = Logging.getLogger(BuilderEntityCard.class
			.getName());
	
	private Card card;
	private long number; 
	
	public BuilderEntityCard(long number){
		//INICIO - EXERC. 6
		super();
		this.number = number;
		EntityManager em = SmartBasicCrudDAO.getInstance().getEntityManagerDAO();
		find(em);
		//FIM - EXERC. 6 #1
	}
	

	
	/**
	 * Get the entity card through your number
	 * 
	 * @param number
	 * @return
	 */
	//# INICIO - EXERC. 6
		public BuilderEntityCard find(EntityManager em) {
			LOGGER.debug("getCardByNumber " + number);
			card = SmartBasicCrudDAO.getInstance().consultaQuerySingle(em,
					Card.class, Card.findByCardNumber, number);
			em.close();
			return this;
		}
		
		public Card getCard(){
			return card;
		}
		//FIM - EXERC. 6 #/
}
